package com.glc.lpp.simulation;

import com.baomidou.springwind.entity.Resource;
import com.baomidou.springwind.enums.ResourceEnum;
import com.glc.lpp.simulation.res.Equipment;
import com.glc.lpp.simulation.res.Operator;
import com.glc.lpp.simulation.res.WorkSpace;
import com.glc.lpp.simulation.workstation.WorkStation;

import java.util.Map;

/**
 * 资源设备工厂
 *
 * @author xin.luo
 * @version V1.0
 * @since 2017/5/11 11:21
 */
public class SimuFactory {

    /**
     * 构造人员资源
     *
     * @param resMap
     * @param resEnum
     * @return
     */
    public static Operator buildOperator(Map<Integer, Resource> resMap, ResourceEnum resEnum) {
        Resource res = resMap.get(resEnum.getType());
        if (res == null) {
            throw new RuntimeException();
        }
        return new Operator(resEnum.getDesc(), res.getAmount().intValue(), res.getAbility());
    }

    /**
     * 构造设备资源
     *
     * @param resMap
     * @param resEnum
     * @return
     */
    public static Equipment buildEquipment(Map<Integer, Resource> resMap, ResourceEnum resEnum) {
        Resource res = resMap.get(resEnum.getType());
        if (res == null) {
            throw new RuntimeException();
        }
        return new Equipment(resEnum.getDesc(), res.getAmount().intValue(), res.getLocomotivity());
    }

    /**
     * 构造区域资源
     *
     * @param resMap
     * @param resEnum
     * @return
     */
    public static WorkSpace buildWorkSpace(Map<Integer, Resource> resMap, ResourceEnum resEnum) {
        Resource res = resMap.get(resEnum.getType());
        if (res == null) {
            throw new RuntimeException();
        }
        return new WorkSpace(resEnum.getDesc(), res.getAmount().intValue());
    }

    /**
     * 构造服务台
     *
     * @return
     */
    public static WorkStation buildWorkStation(Operator operator, Equipment equipment, WorkSpace workSpace, WorkStation next) {
        WorkStation workStation = new WorkStation(operator, equipment, workSpace);
        workStation.setNextWorkStation(next);
        return workStation;
    }

    /**
     * 构造服务台
     *
     * @return
     */
    public static WorkStation buildWorkStation(Equipment equipment, WorkSpace workSpace, WorkStation next) {
        return buildWorkStation(Operator.NULL, equipment, workSpace, next);
    }

    /**
     * 构造服务台
     *
     * @return
     */
    public static WorkStation buildWorkStation(Operator operator, WorkSpace workSpace, WorkStation next) {
        return buildWorkStation(operator, Equipment.NULL, workSpace, next);
    }

    /**
     * 构造服务台
     *
     * @return
     */
    public static WorkStation buildWorkStation(Operator operator, Equipment equipment, WorkStation next) {
        return buildWorkStation(operator, equipment, WorkSpace.NULL, next);
    }


}
